# Tanım: LLVM C++ standard kütüphane.
# URL: https://libcxx.llvm.org/
# Paketçi: Cihan_Alkan
# Gerekler: clang cmake ninja python3 libunwind
# Grup: kütüphane

isim=libc++
surum=7.0.0
devir=1
kaynak=(https://releases.llvm.org/$surum/llvm-$surum.src.tar.xz
        https://releases.llvm.org/$surum/libcxx-$surum.src.tar.xz
        https://releases.llvm.org/$surum/libcxxabi-$surum.src.tar.xz)

derle() {

  [[ -d llvm ]] || mkdir llvm
         mv $SRC/llvm-$surum.src/* ${SRC}/llvm/
  [[ -d llvm/projects/libcxx ]] || mkdir llvm/projects/libcxx

        mv  ${SRC}/libcxx-$surum.src/* ${SRC}/llvm/projects/libcxx/
  [[ -d llvm/projects/libcxxabi ]] || mkdir  llvm/projects/libcxxabi
         mv ${SRC}/libcxxabi-$surum.src/* ${SRC}/llvm/projects/libcxxabi/
  [[ -d build ]] || mkdir build


  cd build
  cmake \
    -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=On \
    -DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=Off \
    ${SRC}/llvm
  ninja cxx cxx_experimental

  cd ${SRC}/build
  DESTDIR="${PKG}" ninja install-libcxx

  # Remove ABI headers.
  rm "${PKG}/usr/include/c++/v1/cxxabi.h"
  rm "${PKG}/usr/include/c++/v1/__cxxabi_config.h"

  # Remove experimental headers.
  rm -rf "${PKG}/usr/include/c++/v1/experimental"

  # License.
  install -Dm644 ${SRC}/llvm/projects/libcxx/CREDITS.TXT "${PKG}/usr/share/licenses/${isim}/CREDITS"
  install -Dm644 ${SRC}/llvm/projects/libcxx/LICENSE.TXT "${PKG}/usr/share/licenses/${isim}/LICENSE"

  cd ${SRC}/build
  DESTDIR="${PKG}" ninja install-libcxxabi
  install -Dm644 ${SRC}/build/include/c++/v1/cxxabi.h "${PKG}/usr/include/c++/v1/cxxabi.h"
  install -Dm644 ${SRC}/build/include/c++/v1/__cxxabi_config.h "${PKG}/usr/include/c++/v1/__cxxabi_config.h"

  install -Dm644 ${SRC}/build/lib/libc++experimental.a ${PKG}/usr/lib/libc++experimental.a
  install -Dm644 -t ${PKG}/usr/include/c++/v1/experimental ${SRC}/build/include/c++/v1/experimental/*
}